package demo

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/demo"
	demoReq "github.com/flipped-aurora/gin-vue-admin/server/model/demo/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type SysStudentApi struct {
}

var sysStudentService = service.ServiceGroupApp.DemoServiceGroup.SysStudentService

// CreateSysStudent 创建SysStudent
// @Tags SysStudent
// @Summary 创建SysStudent
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body demo.SysStudent true "创建SysStudent"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysStudent/createSysStudent [post]
func (sysStudentApi *SysStudentApi) CreateSysStudent(c *gin.Context) {
	var sysStudent demo.SysStudent
	err := c.ShouldBindJSON(&sysStudent)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := sysStudentService.CreateSysStudent(&sysStudent); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteSysStudent 删除SysStudent
// @Tags SysStudent
// @Summary 删除SysStudent
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body demo.SysStudent true "删除SysStudent"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysStudent/deleteSysStudent [delete]
func (sysStudentApi *SysStudentApi) DeleteSysStudent(c *gin.Context) {
	var sysStudent demo.SysStudent
	err := c.ShouldBindJSON(&sysStudent)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := sysStudentService.DeleteSysStudent(sysStudent); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteSysStudentByIds 批量删除SysStudent
// @Tags SysStudent
// @Summary 批量删除SysStudent
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysStudent"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /sysStudent/deleteSysStudentByIds [delete]
func (sysStudentApi *SysStudentApi) DeleteSysStudentByIds(c *gin.Context) {
	var IDS request.IdsReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := sysStudentService.DeleteSysStudentByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateSysStudent 更新SysStudent
// @Tags SysStudent
// @Summary 更新SysStudent
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body demo.SysStudent true "更新SysStudent"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysStudent/updateSysStudent [put]
func (sysStudentApi *SysStudentApi) UpdateSysStudent(c *gin.Context) {
	var sysStudent demo.SysStudent
	err := c.ShouldBindJSON(&sysStudent)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := sysStudentService.UpdateSysStudent(sysStudent); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindSysStudent 用id查询SysStudent
// @Tags SysStudent
// @Summary 用id查询SysStudent
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query demo.SysStudent true "用id查询SysStudent"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysStudent/findSysStudent [get]
func (sysStudentApi *SysStudentApi) FindSysStudent(c *gin.Context) {
	var sysStudent demo.SysStudent
	err := c.ShouldBindQuery(&sysStudent)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if resysStudent, err := sysStudentService.GetSysStudent(sysStudent.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"resysStudent": resysStudent}, c)
	}
}

// GetSysStudentList 分页获取SysStudent列表
// @Tags SysStudent
// @Summary 分页获取SysStudent列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query demoReq.SysStudentSearch true "分页获取SysStudent列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysStudent/getSysStudentList [get]
func (sysStudentApi *SysStudentApi) GetSysStudentList(c *gin.Context) {
	var pageInfo demoReq.SysStudentSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := sysStudentService.GetSysStudentInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
